package com.tanhua.server.controller;

import com.tanhua.common.mapper.SoulQuestionMapper;
import com.tanhua.server.service.TestSoulService;
import com.tanhua.server.vo.Answer;
import com.tanhua.server.vo.TestResultVo;
import com.tanhua.server.vo.TestSoulVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.Array;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 寒
 * @date 2021/6/8
 * @TIME:9:54
 */
@RestController
@Slf4j

public class TestSoulController {
    @Autowired
    TestSoulService testSoulService;


    @GetMapping("/testSoul")
    public ResponseEntity<Object> testSoul() {
        try {
            List<TestSoulVo> testSoulVos = testSoulService.queryTestSoulInfo();

            if (null != testSoulVos) {
                return ResponseEntity.ok(testSoulVos);
            }
        } catch (Exception e) {
            log.error("返回测灵魂数据出错~ ", e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

    @PostMapping("/testSoul")
    public ResponseEntity<Object> testSoulResult(List<Answer> answers) {
        try {

            String id= testSoulService.testSoulScore(answers);

            if (null != id) {
                return ResponseEntity.ok(id);
            }
        } catch (Exception e) {
            log.error("返回测灵魂数据出错~ ", e);
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }
    @GetMapping("testSoul/report/{id}")
    public ResponseEntity<TestResultVo> TestResult(@PathVariable("id") Long id) {
        try {
            TestResultVo testResultVo = this.testSoulService.testResult(id);
            return ResponseEntity.ok(testResultVo);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}